package com.xbongbong.paas.script.controller;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.help.menu.InitFundManagementMenuHelp;
import com.xbongbong.paas.help.menu.InitMenuHelp;
import com.xbongbong.paas.model.PaasAppModel;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.pojo.dto.InitMarketManageMenuDTO;
import com.xbongbong.paas.service.PaasFormService;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.script.pojo.vo.ScriptVO;
import com.xbongbong.saas.model.PaymentSheetModel;
import com.xbongbong.saas.service.PaymentBalanceService;
import com.xbongbong.sys.model.CompanyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * 市场管理菜单初始化
 * @author qcy
 * @version v1.0
 * @date 2020/11/2 10:34
 * @update 2020/11/2 10:34
 * @since v1.0
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/marketActivity/menu")
public class MarketManageMenuScriptController {
    private static final Logger LOG = LoggerFactory.getLogger(MarketManageMenuScriptController.class);

    @Resource
    private ProBaseConfig proBaseConfig;
    @Resource
    private PaasAppModel paasAppModel;
    @Resource
    private PaasMenuModel paasMenuModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private CompanyModel companyModel;
    @Resource
    private PaymentSheetModel paymentSheetModel;
    @Resource
    private InitFundManagementMenuHelp initFundManagementMenuHelp;
    @Resource
    private PaasFormService paasFormService;
    @Resource
    private PaymentBalanceService paymentBalanceService;
    private InitMenuHelp initMenuHelp;

    private static final Integer PRE_PAYMENT_BALANCE = 1;
    private static final Integer PRE_PAY_BALANCE = 2;

    /**
     * 插入资金管理菜单：回款管理、进项发票（付款管理可开发到时再插入）
     * @param InitMarketManageMenuDTO
     * @param br
     * @return java.lang.String
     * @author zcp
     * @date 19/11/4 004 16:20
     * @update 19/11/4 004 16:20
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/init", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String init(@RequestBody @Valid InitMarketManageMenuDTO InitMarketManageMenuDTO, BindingResult br) throws Exception {
        return JSON.toJSONString("{\"msg\":\"success\"}");

    }

    /**
     * 预收款和预付款表单和解释的处理
     * @param InitMarketManageMenuDTO
     * @param br
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/initForm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String initForm(@RequestBody @Valid InitMarketManageMenuDTO InitMarketManageMenuDTO, BindingResult br) throws Exception {
        XbbResponse<ScriptVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
            return JSON.toJSONString(response);
        } else {
            LOG.warn("-----------/script/fund/menu/initForm over");
        }
        return JSON.toJSONString("{\"msg\":\"success\"}");
    }

}
